<template>
    <h2>显示列表</h2>
   券标题<input type="text" v-model="YouHuiName">
   适用门店<select v-model="ShopName">
    <option value="河北石家庄">河北石家庄</option>
    <option value="上海九州">上海九州</option>
    <option value="杭州美食">杭州美食</option>
    <option value="湖南横店">湖南横店</option>
   </select>
   <input type="button"  value="查询" @click="LoadData">
    <table border="1">
        <thead>
            <tr>
                <td>优惠编号</td>
                <td>券标题</td>
                <td>有效日期</td>
                <td>截至日期</td>
                <td>适应门店</td>
                <td>代金券图片</td>
                <td>剩余库存</td>
                <td>减免金额</td> 
                <td>适用业务</td>
                <td>服务电话</td>
                <td>券类型名称</td>
                <td>操作列</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in Info">
                <td>{{item.YouHuiId}}</td>
                <td>{{item.YouHuiName}}</td>
                <td>{{item.YouXiaoTime.substring(0,10)}}-
                {{item.EndTime.substring(0,10)}}</td>
                <td>{{item.ShopName}}</td>
                <td><img   style="width: 60px; height: 70px;" :src="item.Img"></td>
                <td>{{item.YouNum}}</td>
                <td>{{item.JianAmount}}</td> 
                <td>{{item.Remark}}</td>
                <td>{{item.FWPhone.substring(0,4)+"****"+item.FWPhone.substring(6,3)}}</td>
                <td>{{item.TypeName}}</td>
                <td>操作列
                    <a href="#" @click="Delte(item.YouHuiId)" style="margin-right: 20px;">删除</a>
                    <a href="#" @click="Update(item.YouHuiId)" style="margin-right: 20px;">修改</a>
                </td>
            </tr>

        </tbody>
    </table>
当前共{{ pageInfo.totalCount }}条,当前页共{{ pageInfo.pageSize }}条
当前页{{pageInfo.pageIndex  }}/{{ pageInfo.pageCount }}页

<span>
    <a href="#"  style="margin-right: 20px;" @click="PageC('F')">首页</a>
    <a href="#"  style="margin-right: 20px;" @click="PageC('U')">上一页</a>
    <a href="#"  style="margin-right: 20px;" @click="PageC('N')">下一页</a>
    <a href="#"  style="margin-right: 20px;" @click="PageC('E')">尾页</a>
</span>

</template>
<script setup lang="ts">
import axios from 'axios';
import { onMounted,pushScopeId,ref } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter();

//修改
const Update=(Yid:number)=>{


    router.push({
        name:"UpdateYou",
        params:{
            id:Yid
        }
    })

}
//删除
const Delte=(Yid:number)=>{

    if(confirm("确定要删除吗？")){

        
        axios.get('https://localhost:7193/api/YouHui/DeleteYouHui',
        
        {
            params:{
                YouHuiId:Yid
            }
        }

        )
        .then(res=>{
            if(res.data>0){
                alert("删除成功");
                LoadData();
            }
            else{
                alert("删除失败");
            }
        })



    }


}

const YouHuiName=ref("");
const ShopName=ref("");

const Info=ref([{
    YouHuiId:0,
    YouHuiName:"",
    YouXiaoTime:"",
    EndTime:"",
    ShopName:"",
    Img:"",
    YouNum:"",
    JianAmount:"",
    Remark:"",
    FWPhone:"",
    YouHuiTypeId:"",
    TypeName:""


}])




//分页
const pageInfo=ref({

    pageIndex:1,
    pageSize:2,
    totalCount:0,
    pageCount:0


})


onMounted(()=>{
    LoadData();
})
//显示
const LoadData=()=>{

    axios.get('https://localhost:7193/api/YouHui/ShowYouHui',
    
    {
        params:{
            YouHuiName:YouHuiName.value,
            ShopName:ShopName.value,
            pageIndex:pageInfo.value.pageIndex,
            pageSize:pageInfo.value.pageSize


        }
    }
    
    )

    .then(res=>{
        pageInfo.value.pageCount=res.data.PageCount;
        pageInfo.value.totalCount=res.data.TotalCount;

        Info.value=res.data.Data_Info
    })



}
//分页
const PageC=(choose:string)=>{


    switch(choose){
        case "F":
            pageInfo.value.pageIndex=1
            break;
            case "U":
            pageInfo.value.pageIndex=pageInfo.value.pageIndex-1
            break;
            case "N":
            pageInfo.value.pageIndex=pageInfo.value.pageIndex+1
            break;
            case "E":
            pageInfo.value.pageIndex=pageInfo.value.pageCount
            break;
    }

    LoadData();

}

</script>